﻿#pragma once
#include "AsGraphicsObject.h"

__AS_JY(Update 2023.1.7)
namespace AsGraphicsNamespace {

	AS_MEMBER_CLASS_DECLARATION(AsGraphicsPolygonCreator);

	class AS_GRAPHICS_API AsGraphicsPolygonCreator : public AsGraphicsObject, public AsBinder<AsGraphicsPolygonCreator> {
		Q_OBJECT

	public:
		explicit AsGraphicsPolygonCreator(QObject* parent = nullptr);
		explicit AsGraphicsPolygonCreator(AsGraphics* graphics, QObject* parent = nullptr);
		~AsGraphicsPolygonCreator();

	private:
		AS_MEMBER_CLASS(AsGraphicsPolygonCreator)* mp;

	public:
		void create(AsGraphics* graphics, QObject* parent = nullptr);
		void destroy();

	public:
		QVector<QPoint> getPolygonInWidget();
		QVector<QPointF> getPolygon();

	public:
		void reset();
		void addItem(const QPointF& point);
		void undo();

	public:
		void setPolygonStyle(const QPen& pen, const QBrush& brush);
		void setAddTriggerMouseButton(Qt::MouseButton button = Qt::MouseButton::LeftButton);
		void setUndoTriggerMouseButton(Qt::MouseButton button = Qt::MouseButton::RightButton);
		void setAddTriggerKey(Qt::Key key = Qt::Key_Space);
		void setUndoTriggerKey(Qt::Key key = Qt::Key_Backspace);
		void setResetTriggerKey(Qt::Key key = Qt::Key_Escape);
		void setConfirmTriggerKey(Qt::Key key1 = Qt::Key_Enter, Qt::Key key2 = Qt::Key_Return);

	public:
		void setEnable_MouseLeftDoubleClickCommit(bool isEnable);
		void setEnable_MouseRightDoubleClickReset(bool isEnable);
		void setEnable_AutoReset(bool isEnable);
		void setEnable_AutoAdsorp(bool isEnable);
		void setEnable_AutoConfirm_whenPointsEnough(bool isEnable, int amount);
		void setEnable_AutoConfirm_whenButtonRelease(bool isEnable);
		void setEnable_ContinuousAddition(bool isEnable);
		void setEnable_KeepThickness(bool isEnable);

	signals:
		void sigPolygonCommitted(const QVector<QPointF>& points);
		void sigPolygonChanged(const QVector<QPointF>& points);

	};

	typedef AsGraphicsPolygonCreator PolygonCreator;

};

namespace AG = AsGraphicsNamespace;
